package com.lyh.hkcloud.module.common;

import android.app.Activity;
import android.util.Log;
import android.widget.EditText;
import com.lyh.hkcloud.constants.UrlConstants;
import com.lyh.hkcloud.util.base.JsonUtil;
import com.lyh.hkcloud.util.base.LoadingUtils;
import com.lyh.hkcloud.util.base.ToastUtils;
import com.lyh.hkcloud.util.http.Request;
import com.lyh.hkcloud.util.http.listener.json.JsonFailuredListener;
import com.lyh.hkcloud.util.http.listener.json.JsonSuccessListener;
import org.json.JSONObject;

public class WmsService extends ModuleService {

    public WmsService(Activity activity) {
        super(activity);
    }

    public void getWhids(final JsonSuccessListener successListener, final JsonFailuredListener failuredListener) {
        Request.post(activity, UrlConstants.WMS_ROOT + "/baseData/getUserWhid", JsonUtil.getBlankJSONObject(), new JsonSuccessListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                if (!"0000".equals(response.optString("code"))) {
                    ToastUtils.makeText(activity, response.optString("msg"), ToastUtils.LENGTH_SHORT).show();
                    failuredListener.onRespone(response.optString("msg"), null);
                } else {
                    successListener.onRespone(response.optString("msg"), response);
                }
            }
        }, new JsonFailuredListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                Log.e("error",response.optString("message"));
                ToastUtils.makeText(activity, msg, ToastUtils.LENGTH_SHORT).show();
                failuredListener.onRespone(msg, response);
            }
        });
    }

    public void checkBox(final EditText et, JSONObject jsonObject) {
        LoadingUtils.getInstance(activity).show();
        Request.post(activity, UrlConstants.WMS_ROOT + "/baseData/getBox", jsonObject, new JsonSuccessListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                if (!"0000".equals(response.optString("code"))) {
                    ToastUtils.makeText(activity, response.optString("msg"), ToastUtils.LENGTH_SHORT).show();
                    et.setText("");
                    et.requestFocus();
                }
                LoadingUtils.getInstance(activity).hide();
            }
        }, new JsonFailuredListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                Log.e("error",response.optString("message"));
                LoadingUtils.getInstance(activity).hide();
                ToastUtils.makeText(activity, msg, ToastUtils.LENGTH_SHORT).show();
                et.requestFocus();
            }
        });
    }
}
